#include "CreditsState.h"

#include "Game.h"
#include "MainMenuState.h"

void CreditsState::Enter() 
{
	// Getting bitmap font
	GroupFont =	CBitmapFont::GetInstance();

	// Load bitmap font
	FontImageID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("Graphics/Robovox.bmp"), D3DCOLOR_XRGB(0,0,0));

	// Set the bitmap font's values
	GroupFont->SetValues(32, 32, 16, 14, ' ', FontImageID);

	moveUpSpeed = 0;
	SeanTimer = 0;	
}

void CreditsState::Exit() 
{
	// Unload bitmap font
	if(FontImageID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(FontImageID);
		FontImageID = -1;
	}

	moveUpSpeed = 0;
	SeanTimer = 0;	
}

bool CreditsState::Input() 
{
	// If escape return to main menu
	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_ESCAPE)|| CSGD_DirectInput::GetInstance()->JoystickButtonPressed(6))
		Game::GetInstance()->ChangeState(MainMenuState::GetInstance());

	return true;
}

void CreditsState::Update(float elapsed) 
{
	SeanTimer += 0.005;
	if(SeanTimer >= 1)
	{
		moveUpSpeed += 5;
		SeanTimer = 0;
	}
}

void CreditsState::Render() 
{
	// Game Name
	GroupFont->Print("RoBHERT", 32, 32-moveUpSpeed, 3.0f, D3DCOLOR_ARGB(255,0,255,255));

	// Group Names
	GroupFont->Print("Team Boomsauce Members:", 140, 150-moveUpSpeed, 1.0f, D3DCOLOR_ARGB(255,0,255,255));
	GroupFont->Print("Colby Yeates", 340, 250-moveUpSpeed, 1.0f, D3DCOLOR_ARGB(255,0,255,255));
	GroupFont->Print("Sean James", 340, 350-moveUpSpeed, 1.0f, D3DCOLOR_ARGB(255,0,255,255));
	GroupFont->Print("Brandon Jones", 340, 450-moveUpSpeed, 1.0f, D3DCOLOR_ARGB(255,0,255,255));
	GroupFont->Print("Benjamin Feldmann", 340, 550-moveUpSpeed, 1.0f, D3DCOLOR_ARGB(255,0,255,255));

	// Other important people
	GroupFont->Print("Executive Producer:", 140, 650-moveUpSpeed, 1.0f, D3DCOLOR_ARGB(255,0,255,255));
	GroupFont->Print("John O' Leske", 340, 750-moveUpSpeed, 1.0f, D3DCOLOR_ARGB(255,0,255,255));
	GroupFont->Print("Associate Producer:", 140, 850-moveUpSpeed, 1.0f, D3DCOLOR_ARGB(255,0,255,255));
	GroupFont->Print("Robert Martinez", 340, 950-moveUpSpeed, 1.0f, D3DCOLOR_ARGB(255,0,255,255));

	// Return to main menu after everything is off screen
	int lastOff = 950-moveUpSpeed;
	if(lastOff <= 0)
		moveUpSpeed = -1*550;
		//Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
}

CreditsState::CreditsState() 
{
}

CreditsState::CreditsState(CreditsState& menu) 
{
}

CreditsState* CreditsState::GetInstance() 
{
	static CreditsState instance;
	return &instance;
}

CreditsState::~CreditsState()
{

}